/**
 * 4
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-9-19 下午6:53
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, k, p;
    cin >> n >> k >> p;
    vector<int> emps(n);
    vector<int> pass(k);
    for (int i = 0; i < n; ++i) {
        cin >> emps[i];
    }
    for (int i = 0; i < k; ++i) {
        cin >> pass[i];
    }

    sort(emps.begin(), emps.end());
    sort(pass.begin(), pass.end());

    int res = 0x3f3f3f3f;

    for (int i = 0; i <= k - n; ++i) {
        int tmp = 0;
        for (int j = 0; j < n; ++j) {
            int t = abs(emps[j] - pass[i + j]) + abs(pass[i + j] - p);
            tmp = max(tmp, t);
        }
        res = min(tmp, res);
    }

    cout << res << endl;

    return 0;
}